<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>滨江后勤外卖抢单</title>
    <meta name="description" content="">
    <meta name="HandheldFriendly" content="True">
    <meta name="MobileOptimized" content="320">
    <meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui, user-scalable=no">
    <meta http-equiv="cleartype" content="on">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/assets/base/restaurant/courier/css/style.css">
    <!--   <link rel="stylesheet" href="/assets/base/restaurant/courier/css/layer.css">-->
</head>
<body>
<div class="wraper">
    <header class="text-center font-white font-16">
        <div class="back iconfont icon-back"></div>
        订单广场
    </header>
    <div class="search flex">
        <div class="input">
            <input type="text" class="font-12 font-gray2" placeholder="请输入订餐人">
        </div>
        <div class="iconfont icon-sousuo font-white"></div>
    </div>
    <div id="nav">
        <div class="nav text-center clearfix b">
            <div class="nav_list actived pull-left js_nav1" data-id="all">
                <div class="min-tab ">
                    <div class="iconfont icon-all font-18"></div>
                    <p>全部</p>
                </div>
            </div>
            <div class="nav_list pull-left js_nav2" data-id="0">
                <div class="min-tab">
                    <div class="iconfont icon-cai font-18"></div>
                    <p>待备菜(8)</p>
                </div>
            </div>
            <div class="nav_list pull-left js_nav3" data-id="1">
                <div class="min-tab">
                    <div class="iconfont icon-shizhong font-18"></div>
                    <p>待配送(99)</p>
                </div>
            </div>
            <div class="nav_list pull-left js_nav4" data-id="2">
                <div class="min-tab">
                    <div class="iconfont icon-peisong font-18"></div>
                    <p>配送中(100)</p>
                </div>
            </div>
            <div class="nav_list pull-left js_nav5" data-id="3">
                <div class="min-tab">
                    <div class="iconfont icon-wancheng font-18"></div>
                    <p>已送达</p>
                </div>
            </div>
        </div>
    </div>
    <!--全部-->
    <div class="contain js_contain1 " id="all">

        <div class="js_none hide">
            <div class="none">
                <img src="/assets/base/restaurant/courier/images/none.png" alt="">
            </div>
            <p class="text-center font-gray">暂无订单</p>
        </div>

    </div>

    <!--待备菜-->
    <div class="contain js_contain2 hide" id="aprentise">


        <div class="js_none hide">
            <div class="none">
                <img src="/assets/base/restaurant/courier/images/none.png" alt="">
            </div>
            <p class="text-center font-gray js_txt"></p>
        </div>

    </div>

    <!--待配送-->

    <div class="contain js_contain3 hide" id="delivery">

        <div class="js_none hide">
            <div class="none">
                <img src="/assets/base/restaurant/courier/images/none.png" alt="">
            </div>
            <p class="text-center font-gray js_txt"></p>
        </div>
    </div>

    <!--配送中-->

    <div class="contain js_contain4 hide" id="delivering">

        <div class="js_none hide">
            <div class="none">
                <img src="/assets/base/restaurant/courier/images/none.png" alt="">
            </div>
            <p class="text-center font-gray js_txt"></p>
        </div>
    </div>

    <!--已送达-->

    <div class="contain js_contain5 hide" id="finish">

        <div class="js_none hide">
            <div class="none">
                <img src="/assets/base/restaurant/courier/images/none.png" alt="">
            </div>
            <p class="text-center font-gray js_txt"></p>
        </div>
    </div>

    <div class="bottom-hint text-center flex-3"><span class="margin-4 gray2" id="more"></span></div>

</div>
</body>
<script src="/assets/base/restaurant/courier/js/jquery-2.1.0.min.js"></script>
<!--<script src="/assets/base/restaurant/courier/js/layer.js"></script>
<script src="/assets/base/restaurant/courier/js/public.js"></script>-->

<script>

    ajaxData('all');

    var height = $(window).height();
    $('.wraper').css('height', height);
    var header_height = $('header').outerHeight(true);
    var search_height = $('.search').outerHeight(true);
    var nav_height = $('#nav').outerHeight(true);
    $('.contain').css('height', height - search_height - header_height - nav_height);

    $('.nav').on('click', '.nav_list', function () {
        var idx = $(this).index();
        $('.contain').eq(idx).removeClass('hide').siblings('.contain').addClass('hide');
        $(this).addClass('actived').siblings('.nav_list').removeClass('actived');

        var id = $(this).data('id');
        ajaxData(id);
    });

    $(function () {
        var height = $(window).height() - $('.header').outerHeight() - 50;
        $('.contain').css('height', height);
    })
    var page = 0;
    //异步加载订单信息
    $(window).scroll(function (event) {
        page += 2;
        if ($(document).scrollTop() + $(window).height() > $(document).height() - 10) {
            $('.nav_list').each(function () {
                if ($(this).hasClass('actived')) {
                    var id = $(this).data('id');
                    ajaxData(id, page);
                }
            })

        }
    });

    function ajaxData(id, page) {
        if (!page) {
            page = 0;
        }
        $.ajax({
            url: '/base/restaurant/ajaxGoodsData/res_id/{BEESCRM:$res_id}',
            type: 'POST',
            data: {'status': id, 'page': page},
            dataType: 'html',
            success: function (data) {
                if (!data.status && data != '') {
                    if (id == 'all') {
                        if (!page) {
                            $('.box').remove();
                        }
                        $("#all").prepend(data);
                    } else if (id == 0) {
                        if (!page) {
                            $('.box').remove();
                        }
                        $("#aprentise").prepend(data);
                    } else if (id == 1) {
                        if (!page) {
                            $('.box').remove();
                        }
                        $("#delivery").prepend(data);
                    } else if (id == 2) {
                        if (!page) {
                            $('.box').remove();
                        }
                        $("#delivering").prepend(data);
                    } else if (id == 3) {
                        if (!page) {
                            $('.box').remove();
                        }
                        $("#finish").prepend(data);
                    }
                } else if (data.status == 'F') {
                    alert(data.message);
                }

                if (data == '') {
                    $('#more').text('没有更多了');
                }

            }
        });
    }

    /*点击已备菜改变菜品的状态*/
    $(document).on('click', '#tags', function () {
        var text = document.getElementById('tags').innerHTML;
        text = text.replace(/\s+/g, "");//去除空格
        var _this = $(this);
        var data = {};
        data.order_id = $(this).data('order_id');
        data.window_id = $(this).data('window_id');

        if (text == '已备菜') {
            $.ajax({
                url: '/base/restaurant/ajaxGoodsStatus/res_id/{BEESCRM:$res_id}',
                type: 'POST',
                data: data,
                dataType: 'json',
                success: function (res) {
                    if (res.status == 'S') {
                        _this.parents('.box').remove();
                        return false;
                    } else {
                        return false;
                    }
                }
            });
        }


    });
    $('.icon-dianhua').click(function () {
        var number = $(this).siblings('.number').text();
        $(this).attr("href", 'tel:' + number);
    });


</script>
</html>